import { Injectable } from '@angular/core';
import {RequestUtil} from "../../../util/request-util";
import {API} from "../../../constants/constants";
import {MsgResult} from "../../../models/msg-result";
import {Observable} from "rxjs";

@Injectable()
export class DepartmentsService {

  constructor(
    private requestUtil :RequestUtil
  ) { }

  //无参查询
  getDepartments():Observable<MsgResult>{
    return this.requestUtil.get(API.getDepartments);
  }

  //添加部门信息
  insertDepartment(department):Observable<MsgResult> {
    let params="name="+department.name+"&orgId="+department.orgId+
      "&remark="+department.remark+"&isValid="+department.isValid+"&siteType="+department.siteType+"&pId="+department.pId;
    return this.requestUtil.post(API.insertDepartment,params);
  }

  //删除部门信息
  deleteDepartment(id):Observable<MsgResult>{
    let params="id="+id;
    return this.requestUtil.get(API.deleteDepartment,params);
  }

  //根据id查询
  getDepartmentById(id):Observable<MsgResult>{
    let params ="id="+id;
    return this.requestUtil.get(API.getDepartmentById,params);
  }

  //修改部门信息
  updateDepartment(department):Observable<MsgResult>{
    let params="id="+department.id+"&name="+department.name+"&orgId="+department.orgId+
      "&remark="+department.remark+"&isValid="+department.isValid+"&siteType="+department.siteType+"&pId="+department.pId;
    return this.requestUtil.post(API.updateDepartment,params);
  }

//获取站点类型信息
 getDeptSiteType():Observable<MsgResult>{
    return this.requestUtil.get(API.getSiteCategoryInfos);
  }

//获取站点类型信息
  getSiteCategory():Observable<MsgResult>{
    return this.requestUtil.get(API.getSiteCategory);
  }

  /**
   * 获取用户信息
   */
  getLoginAccountType(): Observable<MsgResult> {
    return this.requestUtil.get(API.getLoginAccountType);
  }
  /**
   * 获取组织机构与部门树
   */
  getDepartmentOrgTree(type,orgId): Observable<MsgResult> {
    let params ="orgType="+type+"&orgId="+orgId;
    return this.requestUtil.get(API.getDepartmentOrgTree,params);
  }
}
